package com.atguigu.spzx.product.controller;

import com.atguigu.spzx.model.dto.product.ProductSkuDto;
import com.atguigu.spzx.model.pojo.product.ProductSku;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.h5.ProductItemVo;
import com.atguigu.spzx.product.service.ProductService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/product")
@Tag(name = "商品管理")
public class ProductController {
    //TODO 2025/1/25 服务降级 sentinel
    @Autowired
    private ProductService productService;


    @GetMapping("/{page}/{limit}")
    @Operation(summary = "分页查询")
    public Result<PageInfo<ProductSku>> findPage(@PathVariable("page")Integer pageNum,
                                                 @PathVariable("limit")Integer pageSize,
                                                 ProductSkuDto productSkuDto){
        return Result.ok(productService.findPage(pageNum,pageSize,productSkuDto));
    }

    @GetMapping("getBySkuId/{skuId}")
    @Operation(summary = "获取商品sku信息")
    public Result<ProductSku> getBySkuId(@PathVariable("skuId")Integer skuId){
        return Result.ok(productService.getBySkuId(skuId));
    }

    @GetMapping("item/{skuId}")
    @Operation(summary = "商品详细信息")
    public Result<ProductItemVo> getProductItem(@PathVariable("skuId")Integer skuId){
        return Result.ok(productService.getProductItem(skuId));
    }

    @PutMapping("/auth/updateStormAndSale/{skuId}/{skuNum}")
    @Operation(summary = "售卖成功，更新库存和销量")
    public void updateStormAndSale(@PathVariable Long skuId, @PathVariable Integer skuNum){
        productService.updateStormAndSale(skuId,skuNum);
    }


}
